<?php
class Common extends CI_Controller
{
	public function _load()
	{
		$this->load->model('User_model');
		$this->load->library('user_verification');
	}
	function __construct()
	{
		parent::__construct();
		$this->_load();
	}
	function getCodeForTb()
	{
		$code = $this->input->get('code');
		$reData = $this->common_func->getAccessToken($code);
		$reData = json_decode($reData);
		$access_token = $reData->access_token;
		$refresh_token = $reData->refresh_token;
		$this->db->where('key','access_token');
		$this->db->update('oauth',array('val'=>$access_token));

		$this->db->where('key','refresh_token');
		$this->db->update('oauth',array('val'=>$refresh_token));

		$this->db->where('key','refresh_time');
		$this->db->update('oauth',array('val'=>time()));
		echo '授权成功';
	}
	function getArea()
	{
		$this->db->select();
		$this->db->from('post_'.$_POST['sqlTable']);
		$this->db->where('fatherID',$_POST['fatherId']);
		$data = $this->db->get()->result_array();
		echo json_encode($data);
	}
	function getAreaForId()
	{
		foreach ($_POST as $k=>$v)
		{
			$this->db->select();
			$this->db->from('post_'.$k);
			$this->db->where($k.'ID',$v);
			$sqlData = $this->db->get()->result_array();
			$data[$k] = array('id'=>$sqlData['0'][$k.'ID'],'name'=>$sqlData['0'][$k]);
		}
		echo json_encode($data);
	}
	public function pass_name()
	{
		echo $this->user_verification->is_user_name($_POST['name']);
	}
	function doDownload()
	{
		if(isset($_GET['file']))
		{
			$this->load->helper('download');
			$data = file_get_contents('./upload/'.$_GET['file']); // 读文件内容
			$name = $_GET['file'];
			force_download($name, $data);
		}
		else
		{
			exit('出错！！！');
		}
	}
}